/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.vistas;

import com.mycompany.Controlador.GenericController;
import com.mycompany.entidades.Cliente;
import com.mycompany.entidades.Deuda;
import com.mycompany.entidades.Diario;
import com.mycompany.entidades.Ingreso;
import java.util.Date;
import java.util.List;
import java.lang.Double;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.UIManager;

/**
 *
 * @author wilo
 */
public class VRegistroDeuda extends javax.swing.JFrame {

    /**
     * Creates new form VNuevoCliente
     */
    GenericController<Deuda> controlador = new GenericController();
    List<Deuda> deuda;
    Cliente clienteP;
    boolean nuevo = false;
    boolean bandera = false;
    JButton boton;
    int deudaT = 0;
    int tipo = 0;
    JTextField texto;
    public VRegistroDeuda(Cliente cliente, JTextField texto) {
        this.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/img/1362798841_CellPhone.png")).getImage());
        initComponents();
        this.texto=texto;
        //controlador.indexarPrimeraVez();
        deuda = controlador.findEntities(1, 0, new Deuda());
        clienteP = cliente;

        txtCedula.setText(cliente.getCedula());
        txtNombres.setText(cliente.getNombres());
        txtApellidos.setText(cliente.getApellidos());
        txtCedula.setEditable(false);

        lblTCA.setText("");
        lblTCN.setText("");
        lblTFA.setText("");
        lblTCT.setText("");

        for (int i = 0; i < deuda.size(); i++) {
            if (deuda.get(i).getCedulaCliente().getCedula().compareTo(cliente.getCedula()) == 0) {
                lblTCA.setText(deuda.get(i).getValor() + "");
                if (deuda.get(i).getValor() > 0) {
                    lblTFA.setText(deuda.get(i).getFechaVencimiento() + "");
                }
                deudaT = i;
                bandera = true;
            }
        }
        if (bandera == false) {
            lblTCA.setVisible(false);
            lblTFA.setVisible(false);
            lblTCT.setVisible(false);
            lblCA.setVisible(false);
            lblFA.setVisible(false);
            lblCT.setVisible(false);

            lblTCN.setText("");
        }
    }

    public VRegistroDeuda(Cliente cliente, int a,JTextField texto) {
        this.texto=texto;
        this.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/img/1362798841_CellPhone.png")).getImage());
        initComponents();
        //controlador.indexarPrimeraVez();
        tipo = a;
        deuda = controlador.findEntities(1, 0, new Deuda());
        clienteP = cliente;

        txtCedula.setText(cliente.getCedula());
        txtNombres.setText(cliente.getNombres());
        txtApellidos.setText(cliente.getApellidos());
        txtCedula.setEditable(false);

        lblTCA.setText("");
        lblTCN.setText("");
        lblTFA.setText("");
        lblTCT.setText("");
        jLabel4.setText("Costo:");
        dtFechaVencimiento.setVisible(false);
        jLabel5.setVisible(false);

        for (int i = 0; i < deuda.size(); i++) {
            if (deuda.get(i).getCedulaCliente().getCedula().compareTo(cliente.getCedula()) == 0 && deuda.get(i).getEstado() == 0) {
                lblTCA.setText(deuda.get(i).getValor() + "");
                lblTFA.setText(deuda.get(i).getFechaVencimiento() + "");
                bandera = true;
                deudaT = i;
                txtConcepto.setText(deuda.get(i).getConcepto());
                txtConcepto.setEditable(false);
            }
        }
        if (bandera == false) {
            lblTCA.setVisible(false);
            lblTFA.setVisible(false);
            lblTCT.setVisible(false);
            lblCA.setVisible(false);
            lblFA.setVisible(false);
            lblCT.setVisible(false);
            lblTCN.setText("");
        }
        lblCN.setText("Costo de Pago:");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel13 = new javax.swing.JLabel();
        lblTitulo = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        txtNombres = new javax.swing.JTextField();
        txtApellidos = new javax.swing.JTextField();
        txtCosto = new javax.swing.JTextField();
        cmdGuardar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        dtFechaVencimiento = new com.toedter.calendar.JDateChooser();
        lblCA = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblTCA = new javax.swing.JLabel();
        lblCN = new javax.swing.JLabel();
        lblTCN = new javax.swing.JLabel();
        lblFA = new javax.swing.JLabel();
        lblTFA = new javax.swing.JLabel();
        lblCT = new javax.swing.JLabel();
        lblTCT = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtConcepto = new javax.swing.JTextArea();

        jLabel13.setText("jLabel13");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("DEUDAS");

        lblTitulo.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        lblTitulo.setForeground(new java.awt.Color(26, 45, 245));
        lblTitulo.setText("MANTENIMIENTO DE DEUDAS");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 51, 51));
        jLabel1.setText("Cedula/Ruc:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Nombres:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(51, 51, 51));
        jLabel3.setText("Apellidos:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(51, 51, 51));
        jLabel4.setText("Costo Deuda");

        txtCedula.setEnabled(false);
        txtCedula.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCedulaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCedulaKeyReleased(evt);
            }
        });

        txtNombres.setEnabled(false);
        txtNombres.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombresActionPerformed(evt);
            }
        });

        txtApellidos.setEnabled(false);

        txtCosto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCostoKeyReleased(evt);
            }
        });

        cmdGuardar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        cmdGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/save.png"))); // NOI18N
        cmdGuardar.setText("Guardar");
        cmdGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdGuardarActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/delete.png"))); // NOI18N
        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/diner.png"))); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("Fecha de Vencimiento:");

        dtFechaVencimiento.setDateFormatString("yyyy-MM-dd");
        dtFechaVencimiento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                dtFechaVencimientoKeyReleased(evt);
            }
        });

        lblCA.setForeground(new java.awt.Color(51, 51, 51));
        lblCA.setText("Costo de Deuda Anterior:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(51, 51, 255));
        jLabel8.setText("Deudas de Cliente");

        lblTCA.setText(".....");

        lblCN.setForeground(new java.awt.Color(51, 51, 51));
        lblCN.setText("Costo de Nueva Deuda:");

        lblTCN.setText(".....");

        lblFA.setForeground(new java.awt.Color(51, 51, 51));
        lblFA.setText("Fecha de Vencimiento:");

        lblTFA.setText("......");

        lblCT.setForeground(new java.awt.Color(51, 51, 51));
        lblCT.setText("Costo Total de Deuda:");

        lblTCT.setText(".....");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(51, 51, 51));
        jLabel6.setText("Concepto:");

        txtConcepto.setColumns(20);
        txtConcepto.setLineWrap(true);
        txtConcepto.setRows(5);
        jScrollPane1.setViewportView(txtConcepto);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(dtFechaVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtNombres, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                                        .addComponent(txtApellidos, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtCosto, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane1)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(24, 24, 24))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addComponent(lblTitulo))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(74, 74, 74)
                                .addComponent(cmdGuardar))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(159, 159, 159)
                                .addComponent(jLabel8))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lblCN)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblTCN, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lblCA)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblTCA, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lblCT)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblTCT, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(lblFA)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblTFA, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap(92, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTitulo)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtCosto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(dtFechaVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCA)
                    .addComponent(lblTCA)
                    .addComponent(lblFA)
                    .addComponent(lblTFA))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCN)
                    .addComponent(lblTCN))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCT)
                    .addComponent(lblTCT))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdGuardar)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-582)/2, (screenSize.height-498)/2, 582, 498);
    }// </editor-fold>//GEN-END:initComponents

    private void txtNombresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombresActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombresActionPerformed

    private void cmdGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdGuardarActionPerformed
        // TODO add your handling code here:
        //double parseDouble = Double.parseDouble(lblTCT.getText());
        if (tipo == 0) {
            try {
                Double.parseDouble(txtCosto.getText());
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, "Campo Costo Deuda Erroneo", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            Date d;
            try {
                d = dtFechaVencimiento.getDate();
                String fechaIni = (d.getYear() + 1900) + "-" + (d.getMonth() + 1) + "-" + d.getDate();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, "Campo Fecha de vencimineto vacio", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            Deuda deudaEditar = new Deuda();
            deudaEditar.setCedulaCliente(clienteP);
            deudaEditar.setEstado(0);
            deudaEditar.setFechaVencimiento(d);
            deudaEditar.setConcepto(txtConcepto.getText());
            if (bandera == true) {
                try {
                    double parseDouble = Double.parseDouble(lblTCT.getText());
                    deudaEditar.setIdDeuda(deuda.get(deudaT).getIdDeuda());
                    deudaEditar.setValor(parseDouble);

                    controlador.edit(deudaEditar);
                    JOptionPane.showMessageDialog(rootPane, "Guardado Exitosamente", "Guardar Deuda", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                } catch (Exception ex) {
                    Logger.getLogger(VRegistroDeuda.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            if (bandera == false) {
                try {
                    double parseDouble = Double.parseDouble(lblTCN.getText());
                    deudaEditar.setValor(parseDouble);
                    controlador.create(deudaEditar);

                    JOptionPane.showMessageDialog(rootPane, "Guardado Exitosamente", "Guardar Deuda", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                } catch (Exception ex) {
                    Logger.getLogger(VRegistroDeuda.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        if (tipo == 1) {
            try {
                Double.parseDouble(txtCosto.getText());
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, "Campo Costo Erroneo", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            if (Double.parseDouble(lblTCT.getText()) < 0) {
                JOptionPane.showMessageDialog(rootPane, "Saldo Negativo", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            Deuda deudaEditar = new Deuda();
            deudaEditar.setCedulaCliente(clienteP);
            deudaEditar.setEstado(0);
            deudaEditar.setFechaVencimiento(deuda.get(deudaT).getFechaVencimiento());

            if (bandera == true) {
                try {
                    double parseDouble = Double.parseDouble(lblTCT.getText());
                    deudaEditar.setIdDeuda(deuda.get(deudaT).getIdDeuda());
                    deudaEditar.setValor(parseDouble);

                    if (parseDouble == 0) {
                        deudaEditar.setEstado(1);
                    }

                    controlador.edit(deudaEditar);
                    Date d = new Date();
                    GenericController<Ingreso> contIg = new GenericController<Ingreso>();
                    Ingreso ingreso = new Ingreso();
                    ingreso.setIdUsuario(configuraciones.usuario);
                    ingreso.setFecha(d);
                    ingreso.setConcepto("Pago de deuda");
                    ingreso.setValor(Double.parseDouble(txtCosto.getText()));
                    ingreso.setHora(d.getHours() + ":" + d.getMinutes());
                    contIg.create(ingreso);
                    GenericController<Diario> controladorDiario = new GenericController();
                    String fecha = (d.getYear() + 1900) + "-" + (d.getMonth() + 1) + "-" + d.getDate();
                    List<Diario> diarios = controladorDiario.findWhere(new Diario(), "fecha='" + fecha + "' and idUsuario='" + configuraciones.usuario.getNick() + "'");
                    Diario diario = diarios.get(0);
                    diario.setValor(diario.getValor() + Double.parseDouble(txtCosto.getText()));
                    try {
                        controladorDiario.edit(diario);
                    } catch (Exception ex) {
                        Logger.getLogger(VFactura.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    configuraciones.saldocaja=configuraciones.saldocaja+Double.parseDouble(txtCosto.getText());
                        texto.setText(configuraciones.saldocaja+"");
                    JOptionPane.showMessageDialog(rootPane, "Guardado Exitosamente", "Guardar Deuda", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose();
                } catch (Exception ex) {
                    Logger.getLogger(VRegistroDeuda.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_cmdGuardarActionPerformed

    private void txtCedulaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCedulaKeyPressed

    private void txtCedulaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCedulaKeyReleased
        // TODO add your handling code here:
        Validacion validar = new Validacion();
        validar.numeros(evt, txtCedula);
    }//GEN-LAST:event_txtCedulaKeyReleased

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void txtCostoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCostoKeyReleased
        // TODO add your handling code here:
        Validacion validar = new Validacion();
        validar.decimal(evt, txtCosto);

        lblTCN.setText(txtCosto.getText());
        if (tipo == 1) {
            double num1 = Double.parseDouble(lblTCA.getText());
            double num2 = Double.parseDouble(lblTCN.getText());

            num2 = num1 - num2;
            lblTCT.setText(num2 + "");
        }
        if (bandera == true && tipo == 0) {
            //Double.parseDouble(lblTCA.getText())+Double.parseDouble(lblTCN.getText());
            double num1 = Double.parseDouble(lblTCA.getText());
            double num2 = Double.parseDouble(lblTCN.getText());

            num2 = num1 + num2;
            lblTCT.setText(num2 + "");
        }
    }//GEN-LAST:event_txtCostoKeyReleased

    private void dtFechaVencimientoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtFechaVencimientoKeyReleased
        // TODO add your handling code here:
        Date d = dtFechaVencimiento.getDate();
        String fechaIni = (d.getYear() + 1900) + "-" + (d.getMonth() + 1) + "-" + d.getDate();

    }//GEN-LAST:event_dtFechaVencimientoKeyReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VRegistroDeuda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VRegistroDeuda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VRegistroDeuda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VRegistroDeuda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            System.out.println("Error setting native LAF: " + e);
        }
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VRegistroDeuda(null,null).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdGuardar;
    private com.toedter.calendar.JDateChooser dtFechaVencimiento;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCA;
    private javax.swing.JLabel lblCN;
    private javax.swing.JLabel lblCT;
    private javax.swing.JLabel lblFA;
    private javax.swing.JLabel lblTCA;
    private javax.swing.JLabel lblTCN;
    private javax.swing.JLabel lblTCT;
    private javax.swing.JLabel lblTFA;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JTextField txtApellidos;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextArea txtConcepto;
    private javax.swing.JTextField txtCosto;
    private javax.swing.JTextField txtNombres;
    // End of variables declaration//GEN-END:variables
}
